package controller;

import entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import service.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/demo")
public class DemoController {
    @Resource
    UserService userService;

    @RequestMapping("/f")
    public  String f(){
        return "login";
    }

    @RequestMapping("/login")
    public String Login(@RequestParam(required = false)String userCode,
                        @RequestParam(required = false) String userPassword, HttpSession session){
        User users = userService.getUserById(userCode, userPassword);
        session.setAttribute("users",users);
        if(users==null){
            int zhuce = userService.zhuce(userCode, userPassword);
            return "login";
        }else{
            List<User> userList = userService.searchAll();
            session.setAttribute("userList",userList);
            return "index";
        }
    }

    
   
    
}
